String.prototype.startWith = function (str) {
    if (str == null || str == "" || this.length == 0 || str.length > this.length)
        return false;
    if (this.substr(0, str.length) == str)
        return true;
    else
        return false;
    return true;
}
String.prototype.endWith = function (str) {
    if (str == null || str == "" || this.length == 0 || str.length > this.length)
        return false;
    if (this.substring(this.length - str.length) == str)
        return true;
    else
        return false;
    return true;
}

function createPluginButton(name, icons, functionUrl) {
    var h = '<a class="x-btn x-unselectable x-btn-default-toolbar-small"';
    h = h + 'hidefocus="on" unselectable="on"  onclick="' + functionUrl + '" tabindex="0" ';
    h = h + 'style="top: 2px; margin: 0px;margin-left:5px;">';
    h = h + '<span id="button-1039-btnWrap" data-ref="btnWrap" role="presentation"';
    h = h + 'unselectable="on" style="" class="x-btn-wrap x-btn-wrap-default-toolbar-small ">';
    h = h + '<span id="button-1039-btnEl" data-ref="btnEl" role="presentation" unselectable="on"';
    h = h + 'style="" class="x-btn-button x-btn-button-default-toolbar-small x-btn-text  x-btn-icon x-btn-icon-left x-btn-button-center ">';
    h = h + '<span id="button-1039-btnIconEl" data-ref="btnIconEl" role="presentation"';
    h = h + 'unselectable="on" class="x-btn-icon-el x-btn-icon-el-default-toolbar-small ' + icons + ' "';
    h = h + 'style="">';
    h = h + ' &nbsp;';
    h = h + '</span>';
    h = h + '<span id="button-1039-btnInnerEl" data-ref="btnInnerEl" role="presentation"';
    h = h + 'unselectable="on" class="x-btn-inner x-btn-inner-default-toolbar-small">';
    h = h + name;
    h = h + '</span>';
    h = h + '</span>';
    h = h + '</span>';
    h = h + '</a>';
    return h;
}

function modifyVerf(values) {
    var rondomData = uuid(16, 16);
    var uid = '';
    var ClientDigest = '';
    var browser = DetectBrowser();
    if (browser != "Unknown") {
        createElementNT199();
        var create = DetectNT199Plugin();
        if (create != false) {
            if (1 <= NT199_Find()) {
                var retVal = NT199_CheckPassword("12345678");
                if (retVal == 0) {
                    uid = NT199_GetHardwareId();
                    var randomMessageFromServer = rondomData;
                    ClientDigest = NT199_Sha1WithSeed(randomMessageFromServer);
                }
            }
        }
    }
    values.cmd5 = ClientDigest;
    values.uid = uid;
    values.randomData = rondomData;
}

function uuid(len, radix) {
    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
    var uuid = [], i;
    radix = radix || chars.length;

    if (len) {
        for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
    } else {
        var r;
        uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
        uuid[14] = '4';

        for (i = 0; i < 36; i++) {
            if (!uuid[i]) {
                r = 0 | Math.random() * 16;
                uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
            }
        }
    }

    return uuid.join('');
}

function resizeDialog(w, h) {
    console.log(2);
    var t = 0;
    var l = 0;
    var dw = $(document).height();
    var dh = $(document).height();
    if (w > dw) {
        w = dw - 100;
        l = 50;
    } else {
        l = (dw - w) / 2;
    }
    if (h > dh) {
        h = dh - 100;
        t = 50;
    } else {
        t = (dh - h) / 2;
    }
    $.pdialog.resizeDialog({style: {width: w, left: l, top: t, height: h}}, $.pdialog.getCurrent(), "");
}

function createTreeNavTab(data, pId) {
    var tree;
    if (pId == 0) {
        tree = '<ul class="tree treeFolder expand">';
    } else {
        tree = '<ul>';
    }
    for (var i in data) {
        if (data[i].pId == pId) {
            if (data[i].url == "*") {
                tree += "<li><a href='#'>" + data[i].name + "</a>";
            } else {
                tree += "<li><a href='" + data[i].url + "' target='navTab' rel='nav_" + data[i].id + "'>" + data[i].name + "</a>";
            }
            tree += createTreeNavTab(data, data[i].id);
            tree += "</li>";
        }
    }
    return tree + "</ul>";
}

function moreConditon(isMore) {
    if (isMore == undefined || isMore == 0) {
        $("#isMore", navTab.getCurrentPanel()).val(1);
        $("#pagerForm", navTab.getCurrentPanel()).submit();
    } else {
        $("#isMore", navTab.getCurrentPanel()).val(0);
        $("#pagerForm", navTab.getCurrentPanel()).submit();
    }
}

function clearOrgConditon() {
    $("input[name='orgId']", navTab.getCurrentPanel()).val("");
    $("input[name='orgName']", navTab.getCurrentPanel()).val("");
}
function clearShopConditon() {
    $("input[name='shopId']", navTab.getCurrentPanel()).val("");
    $("input[name='shopName']", navTab.getCurrentPanel()).val("");
    $("input[name='riskShop']", navTab.getCurrentPanel()).val("");
}
function clearChannelConditon() {
    $("input[name='channelId']", navTab.getCurrentPanel()).val("");
    $("input[name='channelName']", navTab.getCurrentPanel()).val("");
}

